package com.aaa.controller.sas;

import com.aaa.dao.sas.TSasPlanMapper;
import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.sas.TSasPlane;
import com.aaa.service.sas.TSasPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("tSasPlane")
public class TSasPlanController {
    @Autowired
    private TSasPlanService tSasPlanService;
    @GetMapping
    public LayData queryAll(MyPage myPage){
        return new LayData(tSasPlanService.queryAll(myPage));
    }
    @PostMapping
    public LayData checkCode(TSasPlane plane){
        return new LayData(tSasPlanService.selectPlan(plane));
    }
    @PostMapping("addPlane")
    public LayData addPlane(TSasPlane plane, HttpSession session){
        if(plane.getId()==null){
            User user1=(User) session.getAttribute("user");
            plane.setCreatetime(new Date());
            plane.setUid(user1.getId());
            return new LayData(tSasPlanService.insertPlane(plane));
        }else{
            return new LayData(tSasPlanService.updatePlan(plane));
        }

    }
    @GetMapping("getByCode")
    public LayData queryByQycode(TSasPlane tSasPlane){
        return new LayData(tSasPlanService.queryByQyCode(tSasPlane));
    }


    @PostMapping ("del")
    @ResponseBody
    public LayData del(TSasPlane tSasPlane){
        boolean del=tSasPlanService.del(tSasPlane);
        System.out.println("===================");
        System.out.println(del);
        return  new LayData(del);
    }
}
